Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assertion when using multiple data imports #2000

Merged
merged 1 commit into from
Jul 21, 2023

Conversation

wtlangford
Copy link
Contributor

@wtlangford wtlangford commented Oct 26, 2019

import "a" as $a;
import "b" as $b;
def f: $a,$b;
f

This fails an assertion: Assertion failed: (var < fr->bc->nlocals), function frame_local_var, file src/execute.c, line 104.

The issue appears to be that we don't properly increment the number of local vars defined in the frame where we STORE_GLOBAL, which means we can easily have more vars stored than we expect in our assertions. The code for STOREV does increment this, so I duplicated that logic into STORE_GLOBAL. I can't think of any ways that this might cause issues. @nicowilliams can you?

These are stored in vars, so we need to make sure that nlocals is large
enough to account for that
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 84.542% when pulling 058ebda on wtlangford:fix-store-global into bda75c3 on stedolan:master.

@irgeek
Copy link

irgeek commented Dec 22, 2020

I just ran into the same issue. It'd be really awesome if this were merged so I didn't have to resort to the hack of concatenating all my data files so I can import them all at once and access them as array members. Alternatively, if importing JSON data is supposed to be restricted to one file, that should be documented.

@lorenzleutgeb
Copy link

lorenzleutgeb commented Feb 21, 2022

I also ran into this just now, assume {a,b}.json exist and are valid JSON, then consider the following snippet:

import "./a" as $a;
import "./b" as $b;

def a: $a;
def b: $b;

When completed with either

{a: a}

or

{b: b}

it will evaluate. However, when completed with

{a: a} * {b: b}

it fails with

jq: src/execute.c:104: frame_local_var: Assertion `var < fr->bc->nlocals' failed.

That's quite confusing, and I spent quite a lot of time figuring out what's going on. Please fix this!

@itchyny
Copy link
Contributor

itchyny commented Jul 20, 2023

LGTM, I will merge this patch with the following test, thank you.

jq -n -c -L tests/modules 'import "data" as $a; import "data" as $b; def f: {$a, $b}; f'

@itchyny itchyny merged commit 5152602 into jqlang:master Jul 21, 2023
itchyny added a commit that referenced this pull request Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants